package cn.herlioner.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

import cn.herlioner.dao.impl.AdministratorDAOImpl;
import cn.herlioner.dao.impl.CollegeDAOImpl;
import cn.herlioner.dao.impl.Obj_StuDAOImpl;
import cn.herlioner.dao.impl.ObjectDAOImpl;
import cn.herlioner.dao.impl.StudentDAOImpl;
import cn.herlioner.pojo.CRUObject;
import cn.herlioner.pojo.Obj_Tea;
import cn.herlioner.pojo.Student;
import cn.herlioner.pojo.TSObject;
import cn.herlioner.service.CRUObjectService;
import cn.herlioner.service.PageService;

public class Demo {
	CRUObject cruObject; 
	List<CRUObject> cruObjects = new ArrayList();
	CRUObjectService cruObjectService = new CRUObjectService();
	ObjectDAOImpl objectDAO = new ObjectDAOImpl();
	private int currentPagechange;//当前�?
	private PageService pageService;
	
	public CRUObject getCruObject() {
		return cruObject;
	}

	public void setCruObject(CRUObject cruObject) {
		this.cruObject = cruObject;
	}

	public List<CRUObject> getCruObjects() {
		return cruObjects;
	}

	public void setCruObjects(List<CRUObject> cruObjects) {
		this.cruObjects = cruObjects;
	}

	public CRUObjectService getCruObjectService() {
		return cruObjectService;
	}

	public void setCruObjectService(CRUObjectService cruObjectService) {
		this.cruObjectService = cruObjectService;
	}

	public ObjectDAOImpl getObjectDAO() {
		return objectDAO;
	}

	public void setObjectDAO(ObjectDAOImpl objectDAO) {
		this.objectDAO = objectDAO;
	}

	public int getCurrentPagechange() {
		return currentPagechange;
	}

	public void setCurrentPagechange(int currentPagechange) {
		this.currentPagechange = currentPagechange;
	}

	public PageService getPageService() {
		return pageService;
	}

	public void setPageService(PageService pageService) {
		this.pageService = pageService;
	}

	@Test
	public void SelectObject() throws IOException{
		
		PageService Pageservice = objectDAO.PageSelect(1, 7);
		
    	//获取组合表里面的组合信息
		try{
			for (int i = 0 ;i<7;i++) {
		    	CRUObject cruObject = new CRUObject();
		    	TSObject obj = (TSObject)Pageservice.getRecordList().get(i);
		    	cruObject = cruObjectService.setobject(obj,cruObject);
		    	cruObjects.add(cruObject);
		    	}
			}catch (IndexOutOfBoundsException e) {
				// TODO: handle exception
				System.out.println("尾页不够pageSize了，但是不影响输出?");
			}
			//如果已经存在信息，则应该删除，然后更新信�?
		System.out.println(cruObjects);
		System.out.println(Pageservice);
    }
	/*
	 *	select * from college co 
		right join (select t.* from teacher te 
		right join (select * from obj_tea ot
		right join tsobject ts on 
		ts.objnum = ot.objnum order by ts.objnum)t on
		te.teanum = t.teanum)la on
		co.clgnum = la.clgnum ; 
	 */
	@Test
	public void pinghe(){
		List<CRUObject> cruObjects= new ArrayList<>();
		SessionFactory sf = new Configuration().configure()
				.buildSessionFactory();
		Session s = sf.openSession();
		cruObjects = s.createQuery("select * from college co "+
							"right join (select t.* from teacher te "+
							"right join (select * from obj_tea ot"+
							"right join tsobject ts order by ts.objnum)t)la with"+
							"co.clgnum = la.clgnum ").list();
		System.out.println(cruObjects);
		s.close();
		sf.close();
	}
	
	@Test
	public void rede() {
		StudentDAOImpl studentDAOImpl =  new StudentDAOImpl();
		Student student = studentDAOImpl.get((long)144108134);
		CollegeDAOImpl clgnamedao = new CollegeDAOImpl();
		System.out.println(clgnamedao.get(student.getSpenum()).getClgname());
	}
	
	@Test
	public void rede12() {
		Obj_StuDAOImpl obj_StuDAOImpl = new Obj_StuDAOImpl();
		PageService pageService = obj_StuDAOImpl.getByPageByStunum(1, 5, (long)144108134);
		pageService.toString();
	}
	
	@Test
	public void rede123() {
		AdministratorDAOImpl administratorDAOImpl = new AdministratorDAOImpl();
		PageService pageService = administratorDAOImpl.PageSelect(1, 5);
		pageService.toString();
	}
}
